<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const arr1 = [1, 2, 3, 4]
      const arr2 = [2, 2, 2, 3] // 1.
      const newArr1 = []
      for (let i = 0; i < arr2.length; i++) {
        if (arr1.indexOf(arr2[i]) !== -1 && newArr1.indexOf(arr2[i]) === -1) {
          newArr1.push(arr2[i])
        }
      }
      console.log(newArr1) //2.

      const newArr2 = arr1.filter((item) => {
        return arr2.includes(item)
      })
      console.log(newArr2)
    </script>
  </body>
</html>
